package com.example.controller;

import com.example.pojo.Result;
import com.example.pojo.exceptionDataPojo;
import com.example.pojo.plcAlarmSettingPojo;
import com.example.pojo.problemDataPojo;
import com.example.service.WorkExceptionRemovalService;
import com.example.service.plcAlarmSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * ClassName:exceptionDataController
 * Description:
 *体系业务化-报警解除业务
 * @Author 赵永峰
 * @Create 2025/3/2 14:18
 * @Version 1.0
 */
@RestController
public class WorkExceptionRemovalController {
    @Autowired
    private WorkExceptionRemovalService workExceptionRemovalService;
    @Autowired
    private plcAlarmSettingService plcAlarmSettingService;
    //电脑端插入一行报警\异常解除的信息
    @PostMapping("/excInsertWorkExceptionRemoval")
    public Result excInsertWorkExceptionRemoval(@RequestBody exceptionDataPojo exceptionDataPojo){
        List<exceptionDataPojo> exceptionDataPojos= workExceptionRemovalService.excInsertOne(exceptionDataPojo);
        return Result.success(exceptionDataPojos);
    }
    //查询所有的报警、异常数据
    @PostMapping("/inquiryExcAllWorkExceptionRemoval")
    public Result inquiryExcAllWorkExceptionRemoval(){
        List<exceptionDataPojo> exceptionDataPojos=workExceptionRemovalService.inquiryAll();
        return Result.success(exceptionDataPojos);
    }
    //对问题库进行操作，插入一条问题数据，返回问题库筛选的内容，这是从“机”环节发出的，因此筛选出所有“机”的问题
    @PostMapping("/problemInsertOneWorkExceptionRemoval")
    public Result problemInsertOneWorkExceptionRemoval(@RequestBody problemDataPojo problemDataPojo){
        //向问题数据库插入一条数据
        workExceptionRemovalService.problemInserOne(problemDataPojo);
        return Result.success("保存成功");
    }
    //数据赋值，向后端筛选是“机”的所有问题，需要的是一个根据一个字段进行筛选
    @PostMapping("/inquiryProblemOneFiledWorkExceptionRemoval")
    public Result inquiryProblemOneFiledWorkExceptionRemoval(@RequestBody Map<String,Object> map){
        //查询，返回一个list
        List<problemDataPojo> pojos=workExceptionRemovalService.inquiryProblemOneFiled(map);
        return Result.success(pojos);
    }
    //辅助函数：对报警/异常问题库的一个行的某一个字段进行修改,修改的值是数字
    @PostMapping("/editOneFiledExceptionDataIntRemoval")
    public Result editOneFiledExceptionDataIntRemoval(@RequestBody Map<String,Object> map){
        workExceptionRemovalService.editOneFiledExceptionDataInt(map);
        return Result.success("修改成功");
    }
    //辅助函数：对问题库，修改一个字段，是字符串
    @PostMapping("/editOneFiledStrProblemWorkException")
    public Result editOneFiledStrProblemWorkException(@RequestBody Map<String,Object> map){
        workExceptionRemovalService.editOneFiledStr(map);
        return Result.success("修改成功");
    }
    //辅助函数：对问题库，修改一个字段，是数字
    @PostMapping("/editOneFiledIntProblemWorkException")
    public Result editOneFiledIntProblemWorkException(@RequestBody Map<String,Object> map){
        workExceptionRemovalService.editOneFiledInt(map);
        return Result.success("修改成功");
    }
    //根据ID，修改一行报警数据,所有的字段都修改
    @PostMapping("excEditOneRowWorkExceptionRemoval")
    public Result excEditOneRowWorkExceptionRemoval(@RequestBody exceptionDataPojo pojo){
        workExceptionRemovalService.excEditOne(pojo);
        return Result.success("修改成功");
    }
    //辅助函数：对报警/异常信息表中，对一个日期类型的数据，筛选≥某一个值，和＜某一个值，
    @PostMapping("/queryExceptionOneFiledScopeWorkExceptionRemoval")
    public Result queryExceptionOneFiledScopeWorkExceptionRemoval(@RequestBody Map<String,Object> map){
        List<exceptionDataPojo> pojos=workExceptionRemovalService.queryExceptionOneFiledScope(map);
        return Result.success(pojos);
    }

    //查询报警信息表中的所有数据，返回查询到的数据（列表格式-新建的plcAlarmSettingPojo类）
    @PostMapping("/selectAllPlcAlarmSettingWorkException")
    public Result selectAllPlcAlarmSettingWorkException(){
        List<plcAlarmSettingPojo> pojos=plcAlarmSettingService.selectAll();
        return Result.success(pojos);
    }
    //依据ID修改报警信息表中的一行数据信息
    @PostMapping("/editOneByIdPlcAlarmSettingWorkException")
    public Result editOneByIdPlcAlarmSettingWorkException(@RequestBody plcAlarmSettingPojo pojo){
        plcAlarmSettingService.editOneById(pojo);
        return Result.success("修改成功");
    }
}
